package cc.idoone.spring_boot_hello.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Component
@PropertySource({ "classpath:first.properties", "classpath:${config.other}.properties" })
public class ConfigurationFileInject {
	@Value("${server.port}")
	private String appPort; // 这里的值来自application.properties，spring
							// boot启动时默认加载此文件

	@Value("${book.name}")
	private String bookName; // 注入第一个配置外部文件属性

	@Value("${book.desc}")
	private String bookDesc; // 注入第二个配置外部文件属性

	@Autowired
	private Environment env; // 注入环境变量对象，存储注入的属性值

	@Override
	public String toString() {
		return "ConfigurationFileInject [appPort=" + appPort + ", bookName=" + bookName
				+ ", bookDesc=" + bookDesc + ", env=" + env + "]";
	}

}
